//Regressions using aggregated data at NAICS-3-digit-Industry-Occupation level

clear all
set more off
qui use GU82_18_A_n3m, replace

qui tsset n3mog year, yearly
sort n3mog year

qui gen nn1=int(n3/100)
qui egen wtcon=mean(n3m_estoccwt), by (n3mog)

qui tsset n3mog year, yearly
sort year

qui gen dp7=0
qui replace dp7=1 if year>2007
foreach a of varlist logrgdpdiff {
qui gen dp7`a'=`a'*dp7
}

//Table B.7
//Driscoll-Kraay
foreach a of varlist n3m_ahr n3m_cqtotben n3m_comp { 
eststo: capture noisily xtscc logdiff`a' logrgdpdiff year dp7logrgdpdiff dp7, fe lag(2)  
esttab, se ar2 stats(N r2)
estimates clear
}

//NAICS-1-digit cluster
drop if missing(logdiffn3m_ahr) | missing(logdiffn3m_cqtotben) | missing(logdiffn3m_comp) // creates irregular years

foreach a of varlist n3m_ahr n3m_cqtotben n3m_comp { 
eststo: capture noisily areg logdiff`a' logrgdpdiff year dp7logrgdpdiff dp7 [pw=n3m_estoccwt], absorb(n3mog) vce(cluster nn1)  
eststo: capture noisily xtreg logdiff`a' logrgdpdiff year dp7logrgdpdiff dp7 [pw=wtcon], fe vce(cluster nn1)  
esttab, se ar2 stats(N r2)
estimates clear
}
